package com.ibm.csr.setup;

import com.ibm.db2.jcc.DB2Binder;

public class BindDriver {


	/**
	 * Bind driver for db2
	 * 
	 * @param host DB2 hostname
	 * @param port DB2 port
	 * @param dbname DB2 database name
	 * @param user username
	 * @param password password
	 * @return true or false
	 */
	public static boolean bindDriver(String host, String port, String dbname,
			String user, String password) {
		String url = "jdbc:db2://" + host + ":" + port + "/" + dbname;
		String[] replace = { "-url", url, "-user", user, "-password", password,
				"-action", "replace" };
		String[] DSNJDBC = { "-url", url, "-user", user, "-password", password,
				"-action", "replace", "-collection", "DSNJDBC", "-keepdynamic",
				"yes" };
		String[] SYSXSR = { "-url", url, "-user", user, "-password", password,
				"-action", "replace", "-collection", "SYSXSR", "-keepdynamic",
				"yes" };
		try {
			DB2Binder.main(replace);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		try {
			DB2Binder.main(DSNJDBC);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		try {
			DB2Binder.main(SYSXSR);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BindDriver.bindDriver("csrec800.vmec.svl.ibm.com", "446", "STLEC1",
				"sysadm", "c0deshop");
	}

}
